package hrm.action.insa.educationaction;

import hrm.action.Action;
import hrm.action.ActionForward;
import hrm.dto.insa.EducationDTO;
import hrm.dto.insa.EmployeeDTO;
import hrm.dto.login.LoginDTO;
import hrm.serviceimple.EducationServiceImple;
import hrm.serviceimple.EmployeeServiceImple;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class InsaEducationListAction implements Action {

	@Override
	public ActionForward execute(HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub
		ActionForward actfoward = new ActionForward();
		EmployeeServiceImple service = EmployeeServiceImple.getInstance();
		EducationServiceImple educationService = EducationServiceImple.getInstance();
		
		EmployeeDTO dto = new EmployeeDTO();
		dto.setId(getFindId(request));
		dto = service.getEmployee(dto);			
		
		EducationDTO edto = new EducationDTO();
		edto.setId(getFindId(request));
		List<EducationDTO> dtolist = educationService.getEducation(edto);
		
		request.setAttribute("employeeDTO", dto);
		request.setAttribute("educationlist", dtolist);

		actfoward.setUrl("getEducation");
		return actfoward;
	}
	
	private String getFindId(HttpServletRequest request){
		
		String findid = (String) request.getSession().getAttribute("findid");
		if(findid == null){
			findid = ((LoginDTO)request.getSession().getAttribute("login")).getId();
			request.setAttribute("findid", findid);
		}
		return findid; 
	}
}
